package com.lesshassles.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.lesshassles.model.*;

/**
 * Controller for the User List screen.
 * @author David Santoro 
 */
public class UserListController implements Controller
{
    private UserBroker userBroker;
    private String successView;
    public static final String MAP_KEY = "users";

    /**
     * Returns a list of User database objects in ModelAndView.
     * @see com.lesshassles.model.User
     */
    public ModelAndView handleRequest(
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        
    	List<User> users = userBroker.getUsers();

        return new ModelAndView(getSuccessView(), MAP_KEY, users);
    }

    public UserBroker getUserBroker() {
        return userBroker;
    }

    public void setUserBroker(UserBroker userBroker) {
        this.userBroker = userBroker;
    }


    public String getSuccessView() {
        return successView;
    }

    public void setSuccessView(String successView) {
        this.successView = successView;
    }
}
